// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_PREPAID_ORDER
// * CreateDate    : 2011/8/16 10:16:40
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:40
// * LastChanger   : 2011/8/16 10:16:40
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;
using ESOL.Business.Mst;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinPrepaidOrder
    /// </summary>
    public partial class FinPrepaidOrderBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinPrepaidOrderEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinPrepaidOrderEntity GetFinPrepaidOrder(FinPrepaidOrderEntity objFinPrepaidOrderEntity)
        {
            return DataAccess.SelectSingle<FinPrepaidOrderEntity>(objFinPrepaidOrderEntity);
        }

        public static FinPrepaidOrderEntity GetByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            FinPrepaidOrderEntity entity = new FinPrepaidOrderEntity();
            entity.PrepaidOrderId = id;
            return DataAccess.SelectSingle<FinPrepaidOrderEntity>(entity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"FPO.*, S.SUPPLIER_FULL_NAME, P.NAME_CN, PO.PURCHASE_ORDER_CODE
                                FROM FIN_PREPAID_ORDER FPO
								LEFT JOIN PUR_PURCHASE_ORDER PO ON PO.PURCHASE_ORDER_ID = FPO.PURCHASE_ORDER_ID
                                LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = PO.SUPPLIER_ID
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = FPO.INVOICE_PERSON
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinPrepaidOrderEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinPrepaidOrder(FinPrepaidOrderEntity objFinPrepaidOrderEntity)
        {
            //return DataAccess.Insert(objFinPrepaidOrderEntity);
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    string code = "";
                    if (MstCodeRuleBs.GetCurrentOrderCode("PrepaidOrder", out code, broker) == false)
                    {
                        broker.RollBack();
                        return false;
                    }
                    objFinPrepaidOrderEntity.InvoiceCode = code;
                    DataAccess.Insert(objFinPrepaidOrderEntity, broker);

                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool InsertFinPrepaidOrder(List<FinPrepaidOrderEntity> objFinPrepaidOrderEntityList)
        {
            return DataAccess.Insert(objFinPrepaidOrderEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinPrepaidOrderEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinPrepaidOrder(FinPrepaidOrderEntity objFinPrepaidOrderEntity)
        {
            return DataAccess.Update(objFinPrepaidOrderEntity);
        }

        public static bool UpdateFinPrepaidOrder(List<FinPrepaidOrderEntity> objFinPrepaidOrderEntityList)
        {
            return DataAccess.Update<FinPrepaidOrderEntity>(objFinPrepaidOrderEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinPrepaidOrderEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinPrepaidOrder(FinPrepaidOrderEntity objFinPrepaidOrderEntity)
        {
            return DataAccess.Delete(objFinPrepaidOrderEntity);
        }

        public static bool DeleteFinPrepaidOrder(List<FinPrepaidOrderEntity> objFinPrepaidOrderEntityList)
        {
            return DataAccess.Delete<FinPrepaidOrderEntity>(objFinPrepaidOrderEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinPrepaidOrderAll()
        {
            return DataAccess.SelectAllDataSet<FinPrepaidOrderEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinPrepaidOrderEntity> GetFinPrepaidOrderAllList()
        {
            return DataAccess.SelectAll<FinPrepaidOrderEntity>();
        }
        #endregion
	}
}	

